package com.fengkai.filepost.pdfoutstream.test.ODsolutions;

import java.util.Arrays;

/**
 * @author Fengkai
 * @creat 2023/4/21
 */
public class OnceChangeGetMinStr {
    public static void main (String[] args) {
        System.out.println(getMinStr("bcdefa"));

    }

    public static String getMinStr (String str) {
        char[] chars = str.toCharArray();
        int index = -1;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] < min) {
                min = chars[i];
                index = i;
            }
        }
        if (index == 0) {
            return str;
        } else {
            char aChar = chars[0];
            chars[0] = chars[index];
            chars[index] = aChar;
            return new String(chars);
        }
    }
}
